'''游戏的状态'''
from util.label import Label

class GameStats:    
    def __init__(self,ai_game):
        self.setting = ai_game.setting
        self.reset_stats()
        self.hight_scroe = 0    # 不重置，游戏期间一直增加

        # 创建记分板
        self.label_score = Label(ai_game, 'right')
        self.label_score.set_text(self.score)
        # 最高分记录
        self.label_hight = Label(ai_game, 'center')
        self.label_hight.set_text(self.hight_scroe)
        # 剩余生命
        self.label_left = Label(ai_game, 'left')
        self.label_left.set_text(self.ships_left)

    def reset_stats(self):
        '''更新飞船的生命'''
        self.ships_left = self.setting.ship_limit
        self.score = 0
        self.level = 1
        # self.show_stats()
    
    def up_score(self,add):
        '''积分增加'''
        self.score += add
        if self.score > self.hight_scroe:
            self.hight_scroe = self.score
    
    def up_level(self):
        '''等级增加'''
        self.level += 1

    def show_stats(self):
        '''显示游戏状态到界面'''
        self.label_score.set_text(f"score:{self.score} level:{self.level}")
        self.label_score.show_text()
        self.label_hight.set_text(f"hight score:{self.hight_scroe}")
        self.label_hight.show_text()
        self.label_left.set_text(f'ship:{self.ships_left}')
        self.label_left.show_text()
